//
//  DreamPictureViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/3/8.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "DreamPictureViewController.h"
#import "LSDrawView.h"
#import "DreamColorViewController.h"
#import "PictureThinkViewController.h"

@interface DreamPictureViewController (){
    LSDrawView *drawView;
}

@end

@implementation DreamPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if (strIsEmpty(self.answer1)) {
        self.title = @"畅想篇";
    }else{
        self.title = @"涂鸦篇";
    }
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatHeadView];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem leftBarButtonItemWithTitle:@"完成" target:self selector:@selector(completePicture)];
}
#pragma mark - 完成绘画
- (void)completePicture{
    PictureThinkViewController *pictureThinkVC = [[PictureThinkViewController alloc]init];
    pictureThinkVC.pictureId = self.pictureId;
    pictureThinkVC.image = [drawView composeImage];
    if (!strIsEmpty(self.answer1)) {
        pictureThinkVC.answer1 = self.answer1;
        pictureThinkVC.answer2 = self.answer2;
    }
    [self.navigationController pushViewController:pictureThinkVC animated:YES];
}
- (void)creatHeadView{
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.frame = CGRectMake((kScreenW - 60)/2, 10, 60, 60);
    titleLabel.text = @"画";
    titleLabel.font = [UIFont systemFontOfSize:25];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = RGBColor(252, 104, 102);
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.clipsToBounds = YES;
    titleLabel.layer.cornerRadius = 30;
    [self.view addSubview:titleLabel];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.text = @"挑选合适的颜色，任凭自己的记忆或感受的涌现，带着这样的心情尽情绘制属于自己独一无二的曼陀罗吧！";
    contentLabel.font = [UIFont systemFontOfSize:16];
    contentLabel.frame = CGRectMake(20, 75, kScreenW - 40, [Global getSizeOfString:contentLabel.text maxWidth:kScreenW - 40 maxHeight:MAXFLOAT withFontSize:16.6].height);
    contentLabel.numberOfLines = 0;
    contentLabel.textColor = KTEXTMAINCOLOR;
    [self.view addSubview:contentLabel];
    
    drawView = [[LSDrawView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(contentLabel.frame) + 5, kScreenW-20, kScreenW-20)];
    drawView.brushColor = [UIColor blueColor];
    drawView.brushWidth = 3;
    drawView.shapeType = LSShapeCurve;
    if (strIsEmpty(self.answer1)) {
        drawView.bgImgView.image = [UIImage imageNamed:@"circular"];
    }else{
         [drawView.bgImgView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl]];
    }
    [self.view addSubview:drawView];
    
    UIView *footView = [[UIView alloc]init];
    footView.frame = CGRectMake( 1, kScreenH - 64 - 41, kScreenW-2, 40);
    footView.backgroundColor = RGBColor(243, 254, 243);
    footView.clipsToBounds = YES;
    footView.layer.borderColor = KBACKNAVIGATIONCOLOR.CGColor;
    footView.layer.borderWidth = 0.5;
    [self.view addSubview:footView];
    
    UILabel *toolText = [[UILabel alloc]init];
    toolText.frame = CGRectMake(20, 10, 80, 20);
    toolText.text = @"绘制工具";
    toolText.textColor = KBACKNAVIGATIONCOLOR;
    toolText.font = [UIFont systemFontOfSize:14];
    [footView addSubview:toolText];
    
    UIButton *rowButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW - 80, 10, 50, 20)];
    [rowButton setImage:[UIImage imageNamed:@"greenTriangle"] forState:UIControlStateNormal];
    [rowButton addTarget:self action:@selector(presentDreamColorVC) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:rowButton];
}
- (void)presentDreamColorVC{
    DreamColorViewController *dreamColorVC = [[DreamColorViewController  alloc]init];
    dreamColorVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    dreamColorVC.clearBlock = ^{
        drawView.isEraser = YES;
        drawView.brushWidth = 6;
    };
    dreamColorVC.selectColorBlock = ^(UIColor *color) {
        drawView.brushWidth = 3;
        drawView.isEraser = NO;
        drawView.brushColor = color;
    };
    [self presentViewController:dreamColorVC animated:YES completion:^{
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
